<template>
    <nav-bar class="goods-nav-bar">
        <template v-slot:left>
            <div @click="handleBackClick">
                <img class="backPic"
                     src="../../../assets/img/common/back.svg" />
            </div>
        </template>
        <template v-slot:center>
            <div class="navbar-title">
                <div v-for="(item,index) in titles"
                     v-bind:key="index"
                     class="navbar-title-item"
                     :class="{'navbar-title-item-active':currentIndex===index}"
                     @click="handleItemClick(index)">{{item}}
                </div>
            </div>
        </template>
    </nav-bar>
</template>
<script>
import NavBar from '../../../components/common/navbar/NavBar';
export default {
    name: 'DetailNavBar',
    components: {
        NavBar,
    },
    data: function () {
        return {
            titles: ['商品', '参数', '评论', '推荐'],
            currentIndex: 0,
        }
    },
    methods: {
        handleItemClick: function (index) {
            this.currentIndex = index;
            this.$emit('titleClick', index)
        },
        handleBackClick: function () {
            this.$router.go(-1);
        }
    }
}
</script>
<style scoped>
.goods-nav-bar {
    background-color: #fff;
    position: relative;
    z-index: 1;
}
.navbar-title {
    display: flex;
    font-size: 14px;
}
.navbar-title-item {
    flex: 1;
}
.navbar-title-item-active {
    color: var(--color-high-text);
}
.backPic {
    width: 20px;
    margin-left: 20px;
    vertical-align: middle;
}
</style>
